package com.t282.crm.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.t282.crm.pojo.CstService;
import com.t282.crm.pojo.SalChance;
import com.t282.crm.service.CstServiceService;
import com.t282.crm.service.SalPlanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mr.Chen
 * @since 2021-05-19
 */
@Controller
@RequestMapping("/salPlan")
public class SalPlanController {
    @Autowired
    private CstServiceService cstServiceService;

    @Autowired
    private SalPlanService salPlanService;

    @RequestMapping ("/list")
    @ApiOperation(value="获取所有分页信息")
    @ResponseBody
    public Page getListPage(@RequestParam(required = false,defaultValue = "1") int pageIndex,
                              @RequestParam(required = false, defaultValue = "") String svrCustName,
                              @RequestParam(required = false, defaultValue = "") String svrDueTo,
                              @RequestParam(required = false, defaultValue = "") String svrTitle,
                              HttpServletRequest request){
        Page<CstService> page = new Page<>(pageIndex,5);
        QueryWrapper<CstService> queryWrapper = new QueryWrapper<>();

        if(svrCustName !=null && svrCustName!=""){
            queryWrapper.like("svr_cust_name",svrCustName);
        }
        if(svrDueTo !=null && svrDueTo!=""){
            queryWrapper.like("svr_due_to",svrDueTo);
        }
        if(svrTitle !=null&& svrTitle!=""){
            queryWrapper.like("svr_title",svrTitle);
        }
        Page<CstService> page1 = cstServiceService.page(page,queryWrapper);

        if (page1!=null){
            request.setAttribute("data",page1);
            request.setAttribute("message","查询成功！");

            return page1;
            //return "/plan/list";
        }else{
            request.setAttribute("message","查询失败！");
            return page1;
        }
    }

    @GetMapping("/getSave")
    public String getSave(@RequestParam Long svrId,HttpServletRequest request){
        CstService byId = cstServiceService.getById(svrId);
        return"";
    }
}

